package cn.algorithms_4ed.base.dataStructure;

import java.util.Iterator;

/**
 * #请替换掉这里的东东#
 * <p/>
 * User: erhu
 * Date: 13-6-11
 * Time: 下午4:44
 */
public class Queue<T> implements Iterable<T> {

    private Node first;
    private Node last;
    private int size;

    private class Node {
        T item;
        Node next;
    }

    public void enqueue(T item) {
        Node old_last = last;
        last = new Node();
        last.item = item;
        last.next = null;
        if (isEmpty()) {
            first = last;
        } else {
            old_last.next = last;
        }
        size++;
    }

    public T dequeue() {
        if (isEmpty()) {
            System.out.print("Queue is empty");
            return null;
        } else {
            T t = first.item;
            first = first.next;
            if (isEmpty()) {
                last = null;
            }
            size--;
            return t;
        }
    }

    public boolean isEmpty() {
        return first == null;
    }

    public int size() {
        return size;
    }

    @Override
    public Iterator<T> iterator() {
        return null;
    }
}
